<template>
  <div id="certificate-container">
    <h2 class="title">道路运输从业资格培训结业证书</h2>
    <p class="text-right">[&nbsp;结业证书编号: {{ studentInfo.finishStudyCode }}&nbsp;]</p>
    <div class="container">
      <p class="desc">
        学员
        <span class="line">{{ studentInfo.name }}</span>
        （身份证号：{{ studentInfo.cardNo }}）于 {{ studentInfo.startStudyDate }} 至 {{
          studentInfo.endStudyDate
        }}
        期间参加我校<span class="line">{{ studentInfo.applyTypeAlias }}</span>
        从业资格培训，并按要求完成了教学大纲规定学时的培训，准予结业！
      </p>
      <div class="picture">
        <img v-if="studentInfo.headImg" :src="getImage(studentInfo.headImg)" fit="['fill']" />
      </div>
    </div>

    <div>(报名编号：{{ studentInfo.enrollBatch }})</div>
    <div class="signature">
      <div class="signature_inner">
        <div>培训单位(盖章)：</div>
        <div class="sign">
          <span>{{ studentInfo.graduationDatetime }}</span>
          <div class="sign_pic">
            <img
              v-if="studentInfo.signaturePhoto"
              :src="getImage(studentInfo.signaturePhoto)"
              fit="['fill']"
            />
          </div>
        </div>
      </div>
      <div class="signtime">{{ dateToChinese(studentInfo.graduationDatetime) }}</div>
    </div>
  </div>
</template>

<script>
import { defineComponent, reactive, toRefs, watch } from "vue-demi"
import { dateToChinese, getImage } from '../../utils/common' 

export default defineComponent({
  name: 'certificated',
  props: {
    childData: {
      type: Object,
      default: () => {}
    }
  },
  setup(prop, { root }) {
    const data = reactive({
      studentInfo: {}
    })

    watch(() => prop.childData, (newVal) => {
      data.studentInfo = { ...newVal }
      const { oneApplyTime, graduationDatetime } = data.studentInfo
      data.studentInfo.startTime = oneApplyTime?.split(' ')[0]
      data.studentInfo.endTime = graduationDatetime?.split(' ')[0]
    }, {
      deep: true,
      immediate: true
    })

    return {
      ...toRefs(data),
      getImage,
      dateToChinese 
    }
  }
}) 
</script>
<style lang="scss" scoped>
#certificate-container {
  border: 1px solid #000000;
  padding: 10px 20px 25px;
  width: 800px;
  box-sizing: border-box;
  .title {
    margin: 10px 0;
    text-align: center;
    font-size: 25px;
  }
  .text-right {
    text-align: right;
  }
  .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    .traintime {
      color: red;
    }
  }
  .desc {
    flex-basis: 80%;
    letter-spacing: 0.1rem;
    line-height: 2.5rem;
    p {
      text-indent: 2em;
    }
    .line {
      padding-bottom: 5px;
      border-bottom: 1px solid #000000;
    }
  }
  .picture {
    flex-basis: 18%;
    img {
      width: 98px;
      height: 137px;
    }
  }
  .signature {
    margin-left: 10px;

    .signature_inner {
      display: flex;
      align-items: center;
      justify-content: flex-end;
      .sign {
        position: relative;
        font-size: 12px;
        font-weight: bold;
        text-align: center;
        display: flex;
        align-items: center;
        .sign_pic {
          width: 100px;
          height: 100px;
          img {
            width: 100%;
            height: 100%;
          }
        }
        span {
          position: absolute;
        }
      }
    }
    .signtime {
      text-align: right;
      padding-right: 120px;
    }
  }
}
</style>
